package com.rfid.analysis;

import android.util.Log;

import java.nio.ByteBuffer;

/**
 * @author Administrator
 * @date 2020/9/17
 */
public class HandlerAddress extends Handler {
    @Override
    public void handleRequest(Message request) {
        if(logOpen) {
            Log.e("handleRequest", "进入HandlerAddress");
        }
        request.setCurrentNodeHandler(this);
        ByteBuffer byteBuffer = request.getBuffer();
        if (byteBuffer.position() + getLength() <= byteBuffer.limit()) {
            byte[] read = new byte[getLength()];
            byteBuffer.get(read);
            request.addData(read);
            request.setAddress(read[0]);
            if (getNext() != null) {
                getNext().handleRequest(request);
            }
        } else {
            byteBuffer.compact();
        }
    }

    public int getLength() {
        return 1;
    }
}